// 自定义网络异常类

// 基础网络异常类
base class NetworkException implements Exception {
  final String message;
  final String? errorCode;
  final dynamic data;

  const NetworkException({
    required this.message,
    this.errorCode,
    this.data,
  });

  @override
  String toString() {
    return '$runtimeType: $message${errorCode != null ? ' (code: $errorCode)' : ''}';
  }
}

// 连接超时异常
final class ConnectionTimeoutException extends NetworkException {
  const ConnectionTimeoutException({
    String message = '连接超时，请检查网络或稍后重试',
    String? errorCode,
    dynamic data,
  }) : super(
          message: message,
          errorCode: errorCode,
          data: data,
        );
}

// 网络连接错误异常
final class NetworkConnectionException extends NetworkException {
  const NetworkConnectionException({
    String message = '网络连接错误，请检查网络连接',
    String? errorCode,
    dynamic data,
  }) : super(
          message: message,
          errorCode: errorCode,
          data: data,
        );
}

// 服务器错误异常
final class ServerException extends NetworkException {
  final int? statusCode;

  const ServerException({
    String message = '服务器错误',
    this.statusCode,
    String? errorCode,
    dynamic data,
  }) : super(
          message: message,
          errorCode: errorCode,
          data: data,
        );

  @override
  String toString() {
    return 'ServerException: $message${statusCode != null ? ' (HTTP $statusCode)' : ''}${errorCode != null ? ' (code: $errorCode)' : ''}';
  }
}

// 授权错误异常
final class AuthException extends NetworkException {
  const AuthException({
    String message = '授权失败，请重新登录',
    String? errorCode,
    dynamic data,
  }) : super(
          message: message,
          errorCode: errorCode,
          data: data,
        );
}

// 请求取消异常
final class RequestCancelledException extends NetworkException {
  const RequestCancelledException({
    String message = '请求已取消',
    String? errorCode,
    dynamic data,
  }) : super(
          message: message,
          errorCode: errorCode,
          data: data,
        );
}

// 业务错误异常（服务器返回非成功状态码）
final class BusinessException extends NetworkException {
  const BusinessException({
    required String message,
    String? errorCode,
    dynamic data,
  }) : super(
          message: message,
          errorCode: errorCode,
          data: data,
        );
}

// 数据解析错误异常
final class DataParsingException extends NetworkException {
  const DataParsingException({
    String message = '数据解析错误',
    String? errorCode,
    dynamic data,
  }) : super(
          message: message,
          errorCode: errorCode,
          data: data,
        );
}